<?php
/**
 * Created by IntelliJ IDEA.
 * User: 张伯发
 * Date: 2019/8/1
 * Time: 11:46
 */

namespace App\Common;


use Swoft\Bean\Annotation\Mapping\Bean;
use Swoft\Bean\Annotation\Mapping\Inject;
use Swoft\Redis\Pool;

/**
 * @Bean()
 * Class Redis
 * @package App\Common
 * @author 张伯发 2019/8/1 11:46
 */
class Redis
{
    /**
     * @Inject()
     * @var Pool
     */
    private $redis;


    public function set(string $key, $value, int $timeout = null)
    {
        return $this->redis->set($key, json_encode($value), $timeout);
    }


    public function get($key)
    {
        $result = $this->redis->get($key);
        if (is_bool($result)) return $result;
        return json_decode($result, true);
    }


    public function getRedis()
    {

        return $this->redis;
    }

}
